<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            轮胎出库
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:30px;">
        </br><div>
        <!-- <div class="aui-btn aui-btn-info aui-btn-block" style="width:40%;margin-left:30%;font-size: 20px;font-weight: bold;" 
            onclick="changeKG()" id="kaiguan"></div> -->
            <div class="aui-btn aui-btn-primary" style="width:40%;margin-left:30%;font-size: 20px;font-weight: bold;background-color: #03a9f4" 
            onclick="changeKG()" id="kaiguan"></div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">
            <table class="table" style='width:120%' id="table">
                <thead>
                    <tr style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <td algin='center' style="width: 150px;">车序号</td>
                        <td algin='center' style="width: 70px;">计划日期</td>
                        <td algin='center' style="width: 150px;">物料号</td>
                        <td algin='center' style="width: 150px;">物料名称</td>
                        <td algin='center' style="width: 50px;">顺序号</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>
    </div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    // var idSelector = "";
    var interval;
    var intervalkg;
    //初始化查询仓库下拉框
    apiready = function() {

        //doSearch();
        //searchKG();
        setInterval("searchKG()","1000");
    }
    function changeKG(){
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/changeTiresOutOfkg";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                kg: 'TiresOutOfKG',
            }
        };

        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    searchKG();

                    //失败
                } else if (myobj.code == "1") {

                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    function searchKG() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getTiresOutOfkg";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                kg: 'TiresOutOfKG',
            }
        };

        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                
                // for(p in myobj){
                //     alert(myobj[p]);
                // }

                if (myobj.code == "0") {
                    var kg = myobj.kg;
                    var div = document.getElementById("kaiguan")
                    if(kg == "0"){//关闭
                        div.innerText="开关:关";
                        div.style.backgroundColor='red';
                        clearInterval(interval)
                    }else if(kg == "1"){
                        div.innerText="开关:开";
                        div.style.backgroundColor='#03a9f4';
                        interval = setInterval("doSearch()","1000");
                    }

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });

    }

    //根据发货单查询表格数据
    function doSearch() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getTiresOutOf";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un
            }
        };

        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {

                    var list = myobj.list;
                    var html = "";

                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;background-color: #F5F5F5;color: black;font-size: 12px;'>";
                        html += "<td name='carno' >" + list[i].carno + "</td>";
                        html += "<td name='planDate' >" + list[i].planDate  + "</td>";

                        html += "<td name='mrlCode' >" + list[i].mrlCode + "</td>";
                        html += "<td name='mrlName' >" + list[i].mrlName + "</td>";

                        html += "<td name='seq' >" + list[i].seq + "</td>";
                        html += "</tr>";
                    }



                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
